package v3.object.command.servoCommand;

import java.util.ArrayList;
import java.util.Map;
import java.util.TreeSet;

import v3.object.STcfg;
import v3.object.command.iCommand;
import v3.object.ship.Ship;
import v3.object.space.Universe;

public class Help extends servoCommand
{

	
	
	public Help()
	{
		super();
		commandName="HELP";
	}

	@Override
	public boolean realExecute (STcfg cfg, Universe universe, Ship ship, Map<String, iCommand> commands, String[] input)
	{
		if(input.length>1)
		{
			iCommand c = commands.get(input[1]);
		
			if (c==null)
			{
				iCommand n = new NoCommand();
				n.execute(cfg, universe, ship, commands, input);
				return false;
			}
			else
			{
				c.getHelp(ship);
			}
		}
		else
		{
			System.out.println("Available Commands: ");
			StringBuilder sb = new StringBuilder();
			ArrayList<String> cmd = new ArrayList<String>(new TreeSet<String>(commands.keySet()));
			int i=1;
			for(String c : cmd)
			{
				sb.append(c);
				sb.append("\t");
				if(i%4 ==0)
					sb.append("\n");
				i++;
			}
			System.out.println(sb.toString());
		}

		return true;
	}
}
